/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StageKedua.java
 *
 * Created on May 12, 2009, 9:55:11 AM
 */

package DigimonAdventure.UserInterface;
import DigimonAdventure.Database.DigimonSpecies;
import DigimonAdventure.Database.Item;
import DigimonAdventure.Database.Loots;
import DigimonAdventure.DigimonAdventure;
import DigimonAdventure.MP3Player.MusicPlayer;
import DigimonAdventure.Things.AbstractDigimon;
import DigimonAdventure.Things.AbstractThings;
import DigimonAdventure.Things.DigimonBaik;
import DigimonAdventure.Things.DigimonBoss;
import DigimonAdventure.Things.Player;
import DigimonAdventure.World.Stage2;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Timer;

/**
 *
 * @author Bebas
 */
public class StageKedua extends javax.swing.JFrame {
    private MusicPlayer bgm;
    private MusicPlayer bgmBattle;
    private MusicPlayer bgmBoss;

    private AbstractDigimon enemy;
    private Player player;
    private Timer timer;

    private Stage2 stage;
    private int eventcheck;
    
    /** Creates new form StageKedua */
    public StageKedua() {
        initComponents();
        bgm  = new MusicPlayer("/DigimonAdventure/Sound/Stage 2.mp3");
        bgmBoss = new MusicPlayer("/DigimonAdventure/Sound/Battle Boss.mp3");
        bgmBattle = new MusicPlayer("/DigimonAdventure/Sound/Battle Standard.mp3");
        player = DigimonAdventure.pemain;
        stage = DigimonAdventure.stage2;
    }

    public void setDigimonLiar(ArrayList<AbstractThings> e){
        for(AbstractThings p: e){
            DigimonLabel temp = new DigimonLabel(p,false);
            this.jLayeredPane1.add(temp,javax.swing.JLayeredPane.MODAL_LAYER);
        }
        Action listener = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                for(Component lbl : jLayeredPane1.getComponentsInLayer(javax.swing.JLayeredPane.MODAL_LAYER)){
                    ((DigimonLabel) lbl).reDraw();
                }
            }
        };
        timer = new Timer(500,listener);
    }

    private void startTheBattle(java.awt.event.MouseEvent evt){
        AbstractThings enemi = stage.getThings(evt.getX(),evt.getY());
        if(enemi != null){
            this.enemy = (AbstractDigimon) enemi;
            if(enemy.isAlive()){
                DialogBattle.setVisible(true);
            }else if(enemy instanceof DigimonBoss && !enemy.isAlive()){
                eventcheck++;





                this.setVisible(false);
                if (eventcheck == 1){
                    if(DigimonAdventure.pemain.getGenderCode() != 3){
                        DigimonAdventure.eventui.setVisible(true);
                    }else{
                        DigimonAdventure.event2ui.setVisible(true);
                    }
                }else{
                    DigimonAdventure.petadunia.setVisible(true);
                }
            }else if(!enemy.isAlive()){

            }
        }
    }

    private void afterBattle(){
        //masih prototipe
        Random rnd = new Random(System.currentTimeMillis());
        if(rnd.nextBoolean()){
            List <Item> itm = Arrays.asList(Item.class.getEnumConstants());
            Collections.shuffle(itm,rnd);
            if(player.getListItem().size() < 10){
                player.addItem(itm.get(itm.size()/2));
            }
        }else{
            List<Loots> loot = Arrays.asList(Loots.class.getEnumConstants());
            Collections.shuffle(loot,rnd);
            if(player.getListLoot().size() < 10){
                player.addLoot(loot.get(loot.size()/2));
            }
        }
        for(DigimonBaik d : player.getListDigimon()){
            if(d != null){
                if(d == player.getActiveDigimon()){
                    d.addExp(enemy.getLvl()* 36 / d.getStrata().getMul());
                }else{
                    d.addExp(enemy.getLvl()* 36 / (2*d.getStrata().getMul()));
                }
            }
        }
        //musuh dihidupkan kembali & bonus exp for boss
        if(enemy instanceof DigimonBoss){
            for(DigimonBaik d : player.getListDigimon()){
                if(d != null){
                    if(d == player.getActiveDigimon()){
                        d.addExp(enemy.getLvl()* 36 / d.getStrata().getMul());
                    }else{
                        d.addExp(enemy.getLvl()* 36 / (2*d.getStrata().getMul()));
                    }
                }
            }
        }else{
            enemy.addLife(enemy.getHP());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        DialogBattle = new javax.swing.JDialog(this);
        OuterPanelArena = new javax.swing.JLayeredPane();
        jLayeredPane2 = new javax.swing.JLayeredPane();
        BGArena = new javax.swing.JLabel();
        PicEnemy = new javax.swing.JLabel();
        PicOwn = new javax.swing.JLabel();
        EnemyDamage = new javax.swing.JLabel();
        OwnDamage = new javax.swing.JLabel();
        CmdAttack = new javax.swing.JButton();
        CmdChange = new javax.swing.JButton();
        CmdSpecial = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        EnemyHPGauge = new javax.swing.JProgressBar();
        OwnHPGauge = new javax.swing.JProgressBar();
        EnemyATBGauge = new javax.swing.JProgressBar();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        OwnName = new javax.swing.JLabel();
        EnemyName = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        OwnATBGauge = new javax.swing.JProgressBar();
        DialogNotification = new javax.swing.JDialog(this);
        jPanel2 = new javax.swing.JPanel();
        Note = new javax.swing.JLabel();
        CmdOK = new javax.swing.JButton();
        OuterPanel = new javax.swing.JLayeredPane();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        BGStage = new javax.swing.JLabel();
        CmdToDigiStat = new javax.swing.JButton();
        CmdToInv = new javax.swing.JButton();
        jLabel63 = new javax.swing.JLabel();
        Countdown = new javax.swing.JLabel();
        jLabel61 = new javax.swing.JLabel();
        Money = new javax.swing.JLabel();
        jLabel62 = new javax.swing.JLabel();
        PlayerName = new javax.swing.JLabel();
        DialogBox = new javax.swing.JScrollPane();
        IsiDialog = new javax.swing.JTextArea();
        PlayerFace = new javax.swing.JLabel();

        DialogBattle.setTitle("The Sacred Altar");
        DialogBattle.setMinimumSize(new java.awt.Dimension(1024, 768));
        DialogBattle.setModal(true);
        DialogBattle.setResizable(false);
        DialogBattle.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentHidden(java.awt.event.ComponentEvent evt) {
                DialogBattleComponentHidden(evt);
            }
            public void componentShown(java.awt.event.ComponentEvent evt) {
                DialogBattleComponentShown(evt);
            }
        });

        BGArena.setIcon(new javax.swing.ImageIcon(getClass().getResource("/DigimonAdventure/Graphics/Arena2.jpg"))); // NOI18N
        BGArena.setBounds(0, 0, 1024, 600);
        jLayeredPane2.add(BGArena, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PicEnemy.setIcon(new javax.swing.ImageIcon(getClass().getResource("/DigimonAdventure/Graphics/empty.gif"))); // NOI18N
        PicEnemy.setBounds(770, 300, 250, 300);
        jLayeredPane2.add(PicEnemy, javax.swing.JLayeredPane.PALETTE_LAYER);

        PicOwn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/DigimonAdventure/Graphics/Celestiamon GS.gif"))); // NOI18N
        PicOwn.setBounds(0, 300, 250, 300);
        jLayeredPane2.add(PicOwn, javax.swing.JLayeredPane.PALETTE_LAYER);

        EnemyDamage.setFont(new java.awt.Font("Tahoma", 0, 24));
        EnemyDamage.setForeground(new java.awt.Color(0, 0, 204));
        EnemyDamage.setBounds(860, 250, 90, 40);
        jLayeredPane2.add(EnemyDamage, javax.swing.JLayeredPane.PALETTE_LAYER);

        OwnDamage.setFont(new java.awt.Font("Tahoma", 0, 24));
        OwnDamage.setForeground(new java.awt.Color(255, 0, 0));
        OwnDamage.setBounds(110, 230, 100, 60);
        jLayeredPane2.add(OwnDamage, javax.swing.JLayeredPane.PALETTE_LAYER);

        jLayeredPane2.setBounds(0, 0, 1024, 600);
        OuterPanelArena.add(jLayeredPane2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        CmdAttack.setText("Attack");
        CmdAttack.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                CmdAttackMouseClicked(evt);
            }
        });
        CmdAttack.setBounds(10, 650, 150, 25);
        OuterPanelArena.add(CmdAttack, javax.swing.JLayeredPane.DEFAULT_LAYER);

        CmdChange.setText("Change Digimon");
        CmdChange.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                CmdChangeMouseClicked(evt);
            }
        });
        CmdChange.setBounds(10, 680, 150, 25);
        OuterPanelArena.add(CmdChange, javax.swing.JLayeredPane.DEFAULT_LAYER);

        CmdSpecial.setText("Special");
        CmdSpecial.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                CmdSpecialMouseClicked(evt);
            }
        });
        CmdSpecial.setBounds(10, 710, 150, 25);
        OuterPanelArena.add(CmdSpecial, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel3.setText("HP");
        jLabel3.setBounds(770, 640, 30, 15);
        OuterPanelArena.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);
        EnemyHPGauge.setBounds(810, 640, 200, 15);
        OuterPanelArena.add(EnemyHPGauge, javax.swing.JLayeredPane.DEFAULT_LAYER);
        OwnHPGauge.setBounds(210, 610, 200, 15);
        OuterPanelArena.add(OwnHPGauge, javax.swing.JLayeredPane.DEFAULT_LAYER);
        EnemyATBGauge.setBounds(810, 660, 150, 15);
        OuterPanelArena.add(EnemyATBGauge, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel1.setText("HP");
        jLabel1.setBounds(170, 610, 30, 15);
        OuterPanelArena.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setText("ATB");
        jLabel2.setBounds(770, 660, 30, 15);
        OuterPanelArena.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        OwnName.setFont(new java.awt.Font("Bitstream Vera Sans Mono", 3, 18));
        OwnName.setText("Itachimon");
        OwnName.setBounds(10, 610, 150, 25);
        OuterPanelArena.add(OwnName, javax.swing.JLayeredPane.DEFAULT_LAYER);

        EnemyName.setFont(new java.awt.Font("Bitstream Vera Sans Mono", 3, 18));
        EnemyName.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        EnemyName.setText("Narutomon");
        EnemyName.setBounds(810, 610, 200, 25);
        OuterPanelArena.add(EnemyName, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel4.setText("ATB");
        jLabel4.setBounds(170, 630, 30, 15);
        OuterPanelArena.add(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);
        OwnATBGauge.setBounds(210, 630, 150, 15);
        OuterPanelArena.add(OwnATBGauge, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout DialogBattleLayout = new javax.swing.GroupLayout(DialogBattle.getContentPane());
        DialogBattle.getContentPane().setLayout(DialogBattleLayout);
        DialogBattleLayout.setHorizontalGroup(
            DialogBattleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(OuterPanelArena, javax.swing.GroupLayout.DEFAULT_SIZE, 1057, Short.MAX_VALUE)
        );
        DialogBattleLayout.setVerticalGroup(
            DialogBattleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(OuterPanelArena, javax.swing.GroupLayout.DEFAULT_SIZE, 768, Short.MAX_VALUE)
        );

        DialogNotification.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        DialogNotification.setMinimumSize(new java.awt.Dimension(400, 150));
        DialogNotification.setModal(true);
        DialogNotification.setResizable(false);

        jPanel2.setMaximumSize(new java.awt.Dimension(400, 100));
        jPanel2.setMinimumSize(new java.awt.Dimension(400, 100));

        Note.setFont(new java.awt.Font("Tahoma", 1, 12));
        Note.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Note.setText("Masukin note disini");

        CmdOK.setText("Ok");
        CmdOK.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                CmdOKMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(Note, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(178, 178, 178)
                        .addComponent(CmdOK, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Note, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(CmdOK, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(28, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout DialogNotificationLayout = new javax.swing.GroupLayout(DialogNotification.getContentPane());
        DialogNotification.getContentPane().setLayout(DialogNotificationLayout);
        DialogNotificationLayout.setHorizontalGroup(
            DialogNotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        DialogNotificationLayout.setVerticalGroup(
            DialogNotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DialogNotificationLayout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Digimon Adventure - Stage II - Wind's Corridor");
        setAlwaysOnTop(true);
        setMinimumSize(new java.awt.Dimension(1024, 768));
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentHidden(java.awt.event.ComponentEvent evt) {
                formComponentHidden(evt);
            }
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        BGStage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/DigimonAdventure/Graphics/Field2.jpg"))); // NOI18N
        BGStage.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                BGStageMouseClicked(evt);
            }
        });
        BGStage.setBounds(0, 0, 800, 600);
        jLayeredPane1.add(BGStage, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLayeredPane1.setBounds(0, 0, 800, 600);
        OuterPanel.add(jLayeredPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        CmdToDigiStat.setFont(new java.awt.Font("Tahoma", 0, 12));
        CmdToDigiStat.setText("Digimon Status");
        CmdToDigiStat.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                CmdToDigiStatMouseClicked(evt);
            }
        });
        CmdToDigiStat.setBounds(830, 20, 170, 25);
        OuterPanel.add(CmdToDigiStat, javax.swing.JLayeredPane.DEFAULT_LAYER);

        CmdToInv.setFont(new java.awt.Font("Tahoma", 0, 12));
        CmdToInv.setText("Inventory");
        CmdToInv.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                CmdToInvMouseClicked(evt);
            }
        });
        CmdToInv.setBounds(830, 60, 170, 25);
        OuterPanel.add(CmdToInv, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel63.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel63.setForeground(new java.awt.Color(204, 0, 102));
        jLabel63.setText("Doom's Countdown:");
        jLabel63.setBounds(470, 690, 143, 17);
        OuterPanel.add(jLabel63, javax.swing.JLayeredPane.DEFAULT_LAYER);

        Countdown.setFont(new java.awt.Font("Tahoma", 3, 11));
        Countdown.setForeground(new java.awt.Color(204, 0, 102));
        Countdown.setText("<Hours> : <Minutes> : <Seconds>");
        Countdown.setBounds(510, 720, 197, 14);
        OuterPanel.add(Countdown, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel61.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel61.setText("Money");
        jLabel61.setBounds(470, 640, 36, 15);
        OuterPanel.add(jLabel61, javax.swing.JLayeredPane.DEFAULT_LAYER);

        Money.setFont(new java.awt.Font("Tahoma", 1, 12));
        Money.setText(": <Player's Money> bits");
        Money.setBounds(520, 640, 200, 15);
        OuterPanel.add(Money, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel62.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel62.setText("Name");
        jLabel62.setBounds(470, 610, 31, 15);
        OuterPanel.add(jLabel62, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PlayerName.setFont(new java.awt.Font("Tahoma", 1, 12));
        PlayerName.setText(": <Player's Name>");
        PlayerName.setBounds(520, 610, 200, 15);
        OuterPanel.add(PlayerName, javax.swing.JLayeredPane.DEFAULT_LAYER);

        IsiDialog.setColumns(20);
        IsiDialog.setEditable(false);
        IsiDialog.setRows(5);
        IsiDialog.setText("---Digimon World Adventure II---\nDanger Level: MEDIUM\nInfection Source: Charademon\n-A very dangerous & cunning digimon created by virus-\n<Has high agility factor>");
        DialogBox.setViewportView(IsiDialog);

        DialogBox.setBounds(10, 610, 450, 100);
        OuterPanel.add(DialogBox, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PlayerFace.setIcon(new javax.swing.ImageIcon(getClass().getResource("/DigimonAdventure/Graphics/FaceM.gif"))); // NOI18N
        PlayerFace.setBounds(840, 520, 180, 225);
        OuterPanel.add(PlayerFace, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(OuterPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 1024, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(OuterPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 768, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CmdToDigiStatMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CmdToDigiStatMouseClicked
        DigimonAdventure.statusui.setVisible(true);
}//GEN-LAST:event_CmdToDigiStatMouseClicked

    private void CmdToInvMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CmdToInvMouseClicked
        DigimonAdventure.inventoriui.setVisible(true);
}//GEN-LAST:event_CmdToInvMouseClicked

    private void CmdAttackMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CmdAttackMouseClicked
        if(OwnATBGauge.getValue() == 100){
            int dmg = player.getActiveDigimon().attack(enemy);
                    if(dmg != 0){
                        EnemyDamage.setText(dmg+"");
                    }else{
                        EnemyDamage.setText("MISS");
                    }
            new Thread(new Runnable() {
                  public void run() {
                        try {
                            EnemyDamage.setVisible(true);
                            Thread.sleep(1500);
                            EnemyDamage.setVisible(false);
                        } catch (InterruptedException ex) {
                        }
                    }
            }).start();
            EnemyHPGauge.setValue(enemy.getLife());
            OwnATBGauge.setValue(0);
        }
}//GEN-LAST:event_CmdAttackMouseClicked

    private void CmdChangeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CmdChangeMouseClicked
        if(OwnATBGauge.getValue() == 100){
        player.nextDigimon();
        if(player.getActiveDigimon() != null && player.getActiveDigimon().getLife() != 0){
            player.getActiveDigimon();
            OwnName.setText(player.getActiveDigimon().getSpecies().toString());
            PicOwn.setIcon(player.getActiveDigimon().getImageIcon());
            OwnHPGauge.setMaximum(player.getActiveDigimon().getHP());
            OwnHPGauge.setValue(player.getActiveDigimon().getLife());
            OwnHPGauge.setValue(player.getActiveDigimon().getLife());
        }else{
            Note.setText("No more Digimons to switch with!");
            DialogNotification.setVisible(true);
        }
        OwnATBGauge.setValue(50);
        }
}//GEN-LAST:event_CmdChangeMouseClicked

    private void CmdSpecialMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CmdSpecialMouseClicked
        if(OwnATBGauge.getValue() == 100){
            if(player.getActiveDigimon().getSpecies() == DigimonSpecies.Gnommon || player.getActiveDigimon().getSpecies() == DigimonSpecies.Moriamon || player.getActiveDigimon().getSpecies() == DigimonSpecies.Gaiamon || player.getActiveDigimon().getSpecies() == DigimonSpecies.Purger_I || player.getActiveDigimon().getSpecies() == DigimonSpecies.Purger_II || player.getActiveDigimon().getSpecies() == DigimonSpecies.Purger_EX){
                int dmg = player.getActiveDigimon().SpecialA(enemy);
                if(dmg != 0){
                        EnemyDamage.setText(dmg+"");
                    }else{
                        EnemyDamage.setText("MISS");
                    }
            }else if(player.getActiveDigimon().getSpecies() == DigimonSpecies.Nymphmon || player.getActiveDigimon().getSpecies() == DigimonSpecies.Atlanmon || player.getActiveDigimon().getSpecies() == DigimonSpecies.Oceamon || player.getActiveDigimon().getSpecies() == DigimonSpecies.Linker_I || player.getActiveDigimon().getSpecies() == DigimonSpecies.Linker_II || player.getActiveDigimon().getSpecies() == DigimonSpecies.Linker_EX){
                int dmg = player.getActiveDigimon().SpecialB(enemy);
                if(dmg != 0){
                        EnemyDamage.setText(dmg+"");
                    }else{
                        EnemyDamage.setText("MISS");
                    }
            }else if(player.getActiveDigimon().getSpecies() == DigimonSpecies.Fayrmon || player.getActiveDigimon().getSpecies() == DigimonSpecies.Seyfermon || player.getActiveDigimon().getSpecies() == DigimonSpecies.Celestiamon || player.getActiveDigimon().getSpecies() == DigimonSpecies.Overseer_I || player.getActiveDigimon().getSpecies() == DigimonSpecies.Overseer_II || player.getActiveDigimon().getSpecies() == DigimonSpecies.Overseer_EX){
                int dmg = player.getActiveDigimon().SpecialC(enemy);
                if(dmg != 0){
                        EnemyDamage.setText(dmg+"");
                    }else{
                        EnemyDamage.setText("MISS");
                    }
            }else{
                int dmg = player.getActiveDigimon().SpecialD(enemy);
                if(dmg != 0){
                        EnemyDamage.setText(dmg+"");
                    }else{
                        EnemyDamage.setText("MISS");
                    }
            }


            new Thread(new Runnable() {
                  public void run() {
                        try {
                            EnemyDamage.setVisible(true);
                            Thread.sleep(1500);
                            EnemyDamage.setVisible(false);
                        } catch (InterruptedException ex) {
                        }
                    }
            }).start();
            EnemyHPGauge.setValue(enemy.getLife());
            OwnHPGauge.setValue(player.getActiveDigimon().getLife());
            OwnATBGauge.setValue(0);
        }
}//GEN-LAST:event_CmdSpecialMouseClicked

    private void CmdOKMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CmdOKMouseClicked
        DialogNotification.setVisible(false);
}//GEN-LAST:event_CmdOKMouseClicked

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        PlayerFace.setIcon(DigimonAdventure.pemain.getImageIcon());
        PlayerName.setText(": "+DigimonAdventure.pemain.getNama());
        Money.setText(": "+String.valueOf(DigimonAdventure.pemain.getBit())+" bits");
        new Thread(bgm).start();
        timer.start();
    }//GEN-LAST:event_formComponentShown

    private void formComponentHidden(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentHidden
        bgm.stopMusic();
        timer.stop();
    }//GEN-LAST:event_formComponentHidden

    private void DialogBattleComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_DialogBattleComponentShown
        bgm.stopMusic();
        if(enemy instanceof DigimonBoss){
            new Thread(bgmBoss).start();
        }else{
            new Thread(bgmBattle).start();
        }
        EnemyName.setText(enemy.getSpecies().toString());
        OwnName.setText(player.getActiveDigimon().getSpecies().toString());
        PicOwn.setIcon(player.getActiveDigimon().getImageIcon());
        PicEnemy.setIcon(enemy.getImageIcon());
        OwnHPGauge.setMaximum(player.getActiveDigimon().getHP());
        OwnHPGauge.setValue(player.getActiveDigimon().getLife());
        EnemyHPGauge.setMaximum(enemy.getHP());
        EnemyHPGauge.setValue(enemy.getLife());
        OwnHPGauge.setValue(player.getActiveDigimon().getLife());

        new Thread (new Runnable() {
            public void run() {
                while(player.getActiveDigimon().isAlive() && enemy.isAlive()){
                    while(OwnATBGauge.getValue() != 100){
                        try {
                            Thread.sleep(player.getActiveDigimon().getSpd().getDelay());
                        } catch (InterruptedException ex) {
                        }
                        OwnATBGauge.setValue(OwnATBGauge.getValue()+1);
                    }
                }
                DialogBattle.setVisible(false);
            }
        },"pemain-menyerang").start();

       new Thread (new Runnable() {
            public void run() {
                while(player.getActiveDigimon().isAlive() && enemy.isAlive()){
                    while(EnemyATBGauge.getValue() != 100){
                        try {
                            Thread.sleep(enemy.getSpd().getDelay());
                        } catch (InterruptedException ex) {
                        }
                        EnemyATBGauge.setValue(EnemyATBGauge.getValue() +1);
                    }
                    OwnDamage.setVisible(true);
                    int dmg = enemy.attack(player.getActiveDigimon());
                    if(dmg != 0){
                        OwnDamage.setText(dmg+"");
                    }else{
                        OwnDamage.setText("MISS");
                    }
                    OwnHPGauge.setValue(player.getActiveDigimon().getLife());
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {}
                    OwnDamage.setVisible(false);
                    EnemyATBGauge.setValue(0);
                }
                //mungkin perlu event??
                afterBattle();
                DialogBattle.setVisible(false);
            }
        },"musuh-menyerang").start();
        
    }//GEN-LAST:event_DialogBattleComponentShown

    private void DialogBattleComponentHidden(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_DialogBattleComponentHidden
        bgmBattle.stopMusic();
        if(enemy instanceof DigimonBoss){
            bgmBoss.stopMusic();
        }else{
            bgmBattle.stopMusic();
        }
        new Thread(bgm).start();
    }//GEN-LAST:event_DialogBattleComponentHidden

    private void BGStageMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_BGStageMouseClicked
        startTheBattle(evt);
    }//GEN-LAST:event_BGStageMouseClicked


    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new StageKedua().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel BGArena;
    private javax.swing.JLabel BGStage;
    private javax.swing.JButton CmdAttack;
    private javax.swing.JButton CmdChange;
    private javax.swing.JButton CmdOK;
    private javax.swing.JButton CmdSpecial;
    private javax.swing.JButton CmdToDigiStat;
    private javax.swing.JButton CmdToInv;
    private javax.swing.JLabel Countdown;
    private javax.swing.JDialog DialogBattle;
    private javax.swing.JScrollPane DialogBox;
    private javax.swing.JDialog DialogNotification;
    private javax.swing.JProgressBar EnemyATBGauge;
    private javax.swing.JLabel EnemyDamage;
    private javax.swing.JProgressBar EnemyHPGauge;
    private javax.swing.JLabel EnemyName;
    private javax.swing.JTextArea IsiDialog;
    private javax.swing.JLabel Money;
    private javax.swing.JLabel Note;
    private javax.swing.JLayeredPane OuterPanel;
    private javax.swing.JLayeredPane OuterPanelArena;
    private javax.swing.JProgressBar OwnATBGauge;
    private javax.swing.JLabel OwnDamage;
    private javax.swing.JProgressBar OwnHPGauge;
    private javax.swing.JLabel OwnName;
    private javax.swing.JLabel PicEnemy;
    private javax.swing.JLabel PicOwn;
    private javax.swing.JLabel PlayerFace;
    private javax.swing.JLabel PlayerName;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel61;
    private javax.swing.JLabel jLabel62;
    private javax.swing.JLabel jLabel63;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables

}
